<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="">
    
    <title>首页</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript" src="../../js/jquery-3.3.1.js"></script>
	<script type="text/javascript" src="../../js/bootstrap.min.js"></script>
	<link href="../../css/bootstrap.min.css" rel="stylesheet">
  </head>
  
  <body>
  <script type="text/javascript">
  	$(document).ready(function(){
  		var url = GetRequest();
  		$.ajax({
  			url:"${pageContext.request.contextPath}/announcement/findByAid",
  			data:{aid : url.aid},
  			dataType:"json",
  			type:"post",
  			success:function(data, status){
  				$("#aname").val(data.data.aname);				
  				$("#content").val(data.data.content);
  		}});
  	});

	function editAnnouncement(){
		var url = GetRequest();
  		$.ajax({
  			url:"${pageContext.request.contextPath}/announcement/edit",
  			data:{aid : url.aid, aname : $("#aname").val(), content : $("#content").val()},
  			dataType:"json",
  			type:"post",
  			success:function(data, status){
  				$("#aname").val(data.data.aname);				
  				$("#content").val(data.data.content);
  				alert(data.message);
  				window.parent.center.location.href='announcementlist.jsp';
  		}});
	}
  	
  	function deleteAnnouncement(){
  		var url = GetRequest();
  		$.ajax({
  			url:"${pageContext.request.contextPath}/announcement/delete",
  			data:{aid : url.aid},
  			dataType:"json",
  			type:"post",
  			success:function(data, status){
  				alert(data.message);
  				window.parent.center.location.href='announcementlist.jsp';
  				window.location.href='announcement.jsp';
  		}});
  	}	
  	
  	function GetRequest() {   
   		var url = location.search; //获取url中"?"符后的字串   
   		var theRequest = new Object();   
   		if (url.indexOf("?") != -1) {   
     		 var str = url.substr(1);   
      		strs = str.split("&");   
      		for(var i = 0; i < strs.length; i ++) {   
         		theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);   
      		}   
   		}   
  		return theRequest;   
	} 
  </script>
<div class="container">
	<div class="row clearfix">
		<div class="col-md-12 column">
		<br/><br/>
			&emsp;&emsp;&emsp;&emsp;标题：<input type="text" id="aname">
			<br/><br/>
			<div class="row clearfix">
				<div class="col-md-4 column">
				</div>
				<div class="col-md-4 column">
					<div class="form-group">
						&emsp;&emsp;&emsp;&emsp;<textarea cols="30" rows="15" id="content"></textarea>
					</div>
									<div class="row clearfix">
						<div class="col-md-4 column">
						</div>
						<div class="col-md-4 column">
						</div>
						<div class="col-md-4 column">
						&emsp;&emsp;&emsp;&emsp;<button type="button" class="btn btn-default" onclick="editAnnouncement()">修改</button>
						&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
						&emsp;&emsp;&emsp;&emsp;<button type="button" class="btn btn-default" onclick="deleteAnnouncement()">删除</button>
						</div>
					</div>
				</div>
				<div class="col-md-4 column">
				</div>
			</div>
		</div>
	</div>
</div>
  </body>
</html>
